package com.fudan.backend.exception;

import com.fudan.backend.util.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BaseException.class)
    public R baseExceptionHandle(BaseException e){
        return new R(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R exceptionHandle(Exception e){
        System.out.println(e.getMessage());
        System.out.println(e);
        return new R(500, "系统错误，请稍后重试");

    }
}
